<template>
  <div class="home">
    <el-backtop target=".right">
      <el-button type="primary" round size="small">
        <i class="fa fa-arrow-up"></i>
        回到顶部
      </el-button>
    </el-backtop>

    <div class="content">
      <div class="left">
        <div class="logo">LUGE-NB</div>
        <el-menu
          class="el-menu-vertical"
          :collapse="false"
          background-color="#000000"
          text-color="whitesmoke"
          active-text-color="#D4F2E7"
          :collapse-transition="false"
          :router="true"
        >
          <el-menu-item v-for="(item,index) in menuList" :key="index" :index="item.router" @click ="click(item.click)"
            ><i :class="item.menuIcon"></i>{{item.menuName}}</el-menu-item
          >
        </el-menu>
      </div>
      <div class="right">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import * as api from "@/js/api";
export default {
  name: "Home",
  components: {},
  data() {
    return {
      testResult: "",
      isCollapse: false,
      menuList:[]
    };
  },
  methods: {
    click(type){
      console.log("数据库点击事件",type)
      if(type.trim()=='logout'){
        console.log("退出成功")
        this.logout();
      }
    },
    getMenuByUser(){
      api.getMenuByUser().then(res=>{
        console.log("加载菜单，",res.data)
        this.menuList = res.data;
      })
    },
    showMenu() {
      this.isCollapse = !this.isCollapse;
    },
    logout() {
      api.logout().then((res) => {
        if (res.status) {
          sessionStorage.clear();
          sessionStorage.setItem("logout",true);
        }
      });
    },
  },
  mounted(){
    this.getMenuByUser()
  }
};
</script>
<style scoped>
.home {
  height: 100%;
  width: 100%;
}
.content {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: row;
}
.el-menu-vertical {
  border-right: solid 1px #000000;
  text-align: left;
}
.el-menu-vertical:not(.el-menu--collapse) {
  width: 250px;
}
.icon {
  font-size: 25px;
  cursor: pointer;
  color: #909399;
}
.left {
  background-color: #000000;
  min-height: 100%;
  box-shadow: 2px 3px 6px black;
}
.menu-top {
  width: 100%;
  height: 6%;
  display: flex;
  flex-direction: row;
}
.show-menu {
  width: 10%;
  text-align: right;
  padding-left: 20px;
  padding-top: 10px;
  padding-right: 15px;
}
.right {
  width: 100%;
  height: 100vh;
  overflow-x: hidden;
  text-align: center;
}
.top {
  height: 6%;
  width: 100%;
  background-color: white;
  color: #303133;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.title {
  font-size: 16px;
  padding-left: 5px;
  cursor: pointer;
}
.user {
  display: flex;
  font-size: 16px;
  align-items: center;
  padding-right: 5px;
}
.message,
.userinfo {
  margin-right: 10px;
}
.message,
.userinfo,
.logout {
  cursor: pointer;
}
.menuTitle {
  width: 90%;
  color: gainsboro;
  font-size: 16px;
  display: flex;
  align-items: center;
  padding-left: 20px;
}
.logo {
  font-size: 20px;
  color: white;
  font-weight: bold;
  padding: 5px;
  text-shadow: 2px 4px 5px #fff;
  cursor: pointer;
}
</style>
